<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;
class UserDonate extends Model
{

    use SoftDelete;

    

    // 表名
//    protected $name = 'GoodsDonate';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
    ];

    public function getImagesAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['images']) ? $data['images'] : '');
        if(!$value){ return  [];}
        $value = explode(',',$value);
        foreach ($value as $k=>&$v){
            $v=get_app_image_url($v);
        }
        return $value;
    }
    /**
     * 根据商户id 获取商品信息
     * */
    public static function getShopList($where=[],$order='id desc',$field='*'){
        $where['status']='1';
        $where['state']='1';
        $list['list'] = self::where($where)
            ->field($field)
            ->order($order)
            ->paginate();
        $list['count'] = self::where($where)
            ->field($field)
//            ->order($order)
            ->count();
        return $list;
    }

    public function cate_id(){
        return $this->belongsTo('GoodsCategory', 'cate_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    /**
     * 详情
     * */
    public static function getInfo($id,$where=[],$field='*'){
        $where['id']=$id;
        $info = self::where($where)
            ->field($field)
            ->find();
        return $info;
    }

}
